
<style>

    .layui-table-cell {
        height: 64px;
        line-height: 64px;
    }
</style>
<div class="layuimini-container layuimini-page-anim" divname="DeviceReport">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="search"> <i class="layui-icon"> </i> 查询 </button>

                <button class="layui-btn layui-btn-sm " lay-event="refresh"> 刷新 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="clearReport"> 清空出入记录 </button>
            </div>
        </script>

        <table class="layui-hide" id="DeviceReportPage" lay-filter="DeviceReportPageTableFilter"> </table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit"> 详情</a>
        </script>
    </div>
</div>

<script>


    layui.use(['form', 'table', 'miniPage', 'element', 'faceAPI'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        var faceAPI = layui.faceAPI;
        form.render();

        IniSearchPar();

        var EnentTypeTable = [];
        EnentTypeTable["1"] = "正常通行(已注册或者陌生人免验证)";
        EnentTypeTable["2"] = "未注册（陌生人）";
        EnentTypeTable["3"] = "有效期已过期或未到起始时间";
        EnentTypeTable["4"] = "通行次数已用尽";
        EnentTypeTable["5"] = "不在开门时段范围";
        EnentTypeTable["6"] = "重复验证";
        EnentTypeTable["7"] = "体温异常";
        EnentTypeTable["8"] = "使用出门按钮开门";
        EnentTypeTable["9"] = "免验证开门";
        EnentTypeTable["10"] = "黑名单验证";
        EnentTypeTable["100"] = "开门超时报警";
        EnentTypeTable["101"] = "门磁报警";
        EnentTypeTable["102"] = "恢复出厂设置";
        EnentTypeTable["103"] = "删除所有人";
        EnentTypeTable["104"] = "开机";
        EnentTypeTable["106"] = "WIFI 已连接";
        EnentTypeTable["107"] = "WIFI 连接已断开";
        EnentTypeTable["108"] = "消防报警";
        EnentTypeTable["109"] = "关闭开门超时报警";
        EnentTypeTable["110"] = "关闭门磁报警";
        EnentTypeTable["111"] = "关闭消防报警";
        EnentTypeTable["112"] = "黑名单报警";
        EnentTypeTable["113"] = "关闭黑名单报警";
        EnentTypeTable["114"] = "门磁开";
        EnentTypeTable["115"] = "门磁关";

        var noteWayTitle = [];//识别介质  0:刷脸，1:打卡，2：编号+密码
        noteWayTitle[0] = "人脸识别";
        noteWayTitle[1] = "刷卡识别";
        noteWayTitle[2] = "编号+密码";

        var notePassTitle = [];
        //识别打卡是否通过 1 or 0
        notePassTitle[0] = "禁止通行";
        notePassTitle[1] = "已放行";



        faceAPI.EnentTypeTable = EnentTypeTable;

        table.render({
            elem: '#DeviceReportPage',
            //**************************异步请求开始***********************
            url: 'api/FaceRecord/GetCardRecordPage',
            method: 'post',
            where: faceAPI.DeviceReportSearchPageResult.field,
            headers: {
                //token: 'sasasas',
                Authorization: "Bearer " + faceAPI.GetJWTToken()
            },//增加Token验证头
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) { //res 即为原始返回的数据
                if (res.errCode == 0) {
                    var data = res.content;
                    var ret = {
                        "code": res.errCode, //解析接口状态
                        "msg": res.error, //解析提示文本
                        "count": data.totalCount, //解析数据长度
                        "data": data.dataList //解析数据列表
                    };
                    return ret;

                } else {
                    /*layer.open({
                        title: '请求错误',
                        content: '(' + res.errCode + ')' + res.error
                    });  */

                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": 0, //解析数据长度
                        "data": [] //解析数据列表
                    };
                }

            }, //**************************异步请求结束***********************

            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { field: 'date', width: 200, title: '时间', sort: true },
                { field: 'deviceSn', width: 160, title: '设备SN', sort: true },
                { field: 'code', width: 140, title: '人员编号', sort: true },
                { field: 'name', width: 140, title: '人员姓名', sort: true },
                { field: 'card', width: 150, title: '卡号', sort: true },
                {//打卡事件
                    field: 'event', title: '事件', sort: true
                },
                {//是否已放行
                    field: 'enter', title: '进出方向', sort: true,
                    templet: function (d) {
                        if (d.enter == 0)
                            return "进";
                        else
                            return "出";
                    }
                },
                {
                    field: '', width: 100, title: '体温', sort: true,
                    templet: function (d) {
                        if (d.temp > 0) {
                            return d.temp + '℃';
                        }
                        else
                            return '无';

                    }
                },
                {
                    field: '', width: 120, title: '现场照片', sort: true,
                    templet: function (d) {
                        if (d.photo!=null&&d.photo.length > 0) {
                            return '<img src = "' + d.photo + '"  height="60"/>';
                        }
                        else
                            return '无';

                    }
                },
                { title: '操作', width: 80, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [100, 200, 300, 400, 500, 600],
            limit: 100,
            page: true,
            skin: 'line'
        });




        function IniSearchPar() {
            var par = {
                field: {
                    reportBegin: dayjs().subtract(7, 'day').format("YYYY-MM-DD") + ' 00:00:00',
                    reportEnd: dayjs().format("YYYY-MM-DD") + ' 23:59:59',
                },
                result: true
            };

            faceAPI.DeviceReportSearchPageResult = par;
        }
        /**
         * toolbar事件监听
         */
        table.on('toolbar(DeviceReportPageTableFilter)', function (obj) {
            if (obj.event === 'search') {  // 查询操作
                var content = miniPage.getHrefContent('page/DeviceReport/search.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '搜索出入记录',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                    end: function (layero, index) {

                        refreshTable(false);

                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
            else if (obj.event == 'refresh') {
                //执行搜索重载
                refreshTable(true);
            }
            else if (obj.event == 'clearReport') {
                layer.confirm('操作确认：清空所有出入记录？', function (index) {
                    faceAPI.Ajax({
                        type: 'post',
                        url: '/api/FaceRecord/ClearReport',
                        success: function (result) {
                            if (result.result == false) {
                                layer.alert(result.error, { icon: 2 });
                            }
                            else {
                                refreshTable(true);
                            }

                        }

                    });
                    layer.close(index);
                });
            };

        });
        function refreshTable(bIni) {
            if (bIni) IniSearchPar();
            var rst = faceAPI.DeviceReportSearchPageResult;
            table.reload('DeviceReportPage', {
                page: {
                    curr: 1
                }, where: rst.field
            }, 'data');
        }


        table.on('tool(DeviceReportPageTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {

                var content = miniPage.getHrefContent('page/DeviceReport/Detail.html');
                var openWH = miniPage.getOpenWidthHeight();
                faceAPI.DeviceReportDetail = data;//向layer页面传值，传值主要代码
                var index = layer.open({
                    title: '日志详情',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }

        });
    }
    );



</script>
